package br.com.websec.boleto;

import javax.faces.context.FacesContext;
import javax.servlet.http.HttpServletResponse;

import br.com.websec.util.FuncoesUtil;

public class DownloadBoleto {
	
	public static void download(byte[] arquivo, String filename) {   
        HttpServletResponse response;  
        try {  
            response = (HttpServletResponse) FacesContext.getCurrentInstance().getExternalContext().getResponse();  
            response.setContentType("application/pdf");  
        response.addHeader("Content-Disposition", "attachment; filename=" + filename);  
            response.setContentLength(arquivo.length);  
                response.getOutputStream().write(arquivo);  
                response.getOutputStream().flush();  
                response.getOutputStream().close();  
  
          //  FacesContext.getCurrentInstance().responseComplete();  
        }catch (Exception e) {  
            FuncoesUtil.mensagemInforma("Erro ao disponibilizar o arquivo para download !");  
        }  
    }  

}
